#coding:utf-8
'''
import  os,re,time,subprocess,threading

class AndroidCrash_Code(object):
    def __init__(self):
        self.LOG = os.path.join(os.getcwd(),'androidLog','alllog.feng_test_logfile') #定义alllog路径
        self.CrashLog=os.path.join(os.getcwd()+'androidLog'+'CrashLogCode.feng_test_logfile')#定义 Crashlogcode路径
        self.crashCount = 0
        self.anyCount = 0
        self.stopLog_code = True
        #正则匹配
        self.HEAD_REGEX = r"[0-9][0-9]-[0-2][0-9]\s[0-2][0-9](:[0-5][0-9]){2}.\d{3}\sE/"
        self.ANR_REGEX = self.HEAD_REGEX+r"ActivityManager+\(.*\):\sANR\sin.*"
        self.CRASH_REGEX = self.HEAD_REGEX+r"AndroidRuntime.*"
        self.COMMON_REGEX =  r"^(0[0-9]1[0-2])-[0-2][0-9]\s[0-2][0-9](:[0-5][0-9]){2}.[\d]+\s+[\d]+\s+[\d]+\s+[VDIWE]\\s.*"
    def startLog(self):
        print('>>>>>>start  android feng_test_logfile monitor')
        self.monitor=threading.Thread(target=self.huoQu_androidLog)
        self.monitor.setDaemon()
        self.monitor.start()
        self.parseManager=threading.Thread(target=self.jieXi_LOG)
        self.parseManager.setDaemon()
        self.parseManager.start()
        self.monitor.setDaemon()
    def stopLog(self):
        self.stopLog=False



    def huoQu_androidLog(self):
        os.popen("adb logcat -c")  #os.popen 读取出执行的内容
        subprocess.Popen('adb  logcat -v time>{}'.format(self.LOG)) #subprocess 用子线程定向输出所有日志到指定文件
    def jieXi_LOG(self):  #解析日志
        crashLog=open(self.CrashLog,"w")
        cmd = ('tail','-f',self.LOG)  #从控制台打印日志 监听在txt中生成的日志！
        output =subprocess.Popen(cmd,stdout=subprocess.PIPE,shell=True)  #让输入不在控制台输出，当前时间点读取到的log，
                                                                            # 他是一个秩持续读取新增log的过程！
        while self.stopLog==True:
            line=output.stdout.readline()      #输出标准的命令行log日志
            if  not line:
                time.sleep(0.05)
                continue
            if re.match(self.ANR_REGEX,line):
                if re.match(self.HEAD_REGEX +   r'AndroidRuntime+\(.*\):\sProcess.*', line): #表示crash崩溃日志的第一句
                    self.crashCount+=1
                    crashLog.write('***************************************************************************')
                    crashLog.write('fengFan  found crash Number {}'.format(self.crashCount))

                crashLog.write(line)

            #if re.compile(self.CRASH_REGEX.match(line)):

             #       crashLog.write('*************************************************************')
              #  print(line)
               # continue
'''